<?php
class BaseModelLog {
	public static function write($type, $msg) {
		defined('LOG_ERROR') || define('LOG_ERROR', 2);
		defined('LOG_ERR')   || define('LOG_ERR', LOG_ERROR);
		$levels = array(
			LOG_WARNING => 'warning',
			LOG_NOTICE => 'notice',
			LOG_INFO => 'info',
			LOG_DEBUG => 'debug',
			LOG_ERR => 'error',
			LOG_ERROR => 'error'
		);

		if (is_int($type) && isset($levels[$type])) {
			$type = $levels[$type];
		}

		if ($type == 'error' || $type == 'warning') {
			$filename = LOGS_PATH . 'error.log';
		} 
		elseif (in_array($type, $levels)) {
			$filename = LOGS_PATH . 'debug.log';
		} 
		else {
			$filename = LOGS_PATH . $type . '.log';
		}
		$output = date('Y-m-d H:i:s') . ' ' . ucfirst($type) . ': ' . $msg . "\n";
		$log = new File($filename, true);
		if ($log->writable()) {
			return $log->append($output);
		}
	}
}
?>